package org.gap.web.jsf;

import java.util.List;

import org.gap.dao.CaractPMDAO;
import org.gap.dao.TiersDAO;

import org.gap.domain.CaractPM;
import org.gap.domain.Tiers;

import org.gap.service.CaractPMService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Component;

import org.springframework.transaction.annotation.Transactional;

/**
 * Spring Component that handles CRUD requests for CaractPM entities
 * 
 */
@Scope("session")
@Component("CaractPMComponent")
public class CaractPMComponentImpl implements CaractPMComponent {

	/**
	 * Data type variable that provides CRUD operations for CaractPM entities
	 * 
	 */
	private CaractPM caractpm;

	/**
	 * DAO injected by Spring that manages Tiers entities
	 * 
	 */
	private Tiers tiers;

	/**
	 * DAO injected by Spring that manages CaractPM entities
	 * 
	 */
	@Autowired
	private CaractPMDAO caractPMDAO;

	/**
	 * DAO injected by Spring that manages Tiers entities
	 * 
	 */
	@Autowired
	private TiersDAO tiersDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for CaractPM entities
	 * 
	 */
	@Autowired
	private CaractPMService caractPMService;

	/** 
	 */
	public CaractPMComponentImpl() {
	}

	/**
	 * Select the CaractPM entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteCaractPM(Integer cpmTiersKey) {
		caractpm = caractPMDAO.findCaractPMByPrimaryKey(cpmTiersKey);

		return "/jsf/caractpm/deleteCaractPM.xhtml";
	}

	/**
	 * Get Tiers entity by CaractPM
	 * 
	 */
	@Transactional
	public Tiers getCaractPMTiers(Integer cpmTiersKey) {
		return caractPMDAO.findCaractPMByPrimaryKey(cpmTiersKey).getTiers();
	}

	/**
	 * Save an existing CaractPM entity
	 * 
	 */
	@Transactional
	public String saveCaractPM(CaractPM caractpm) {
		caractPMService.saveCaractPM(caractpm);
		return "/jsf/caractpm/listCaractPMs.xhtml";
	}

	/**
	 * Edit an existing Tiers entity
	 * 
	 */
	@Transactional
	public String editCaractPMTiers(Integer caractpm_cpmTiers, Integer related_tiers_tieTiers) {
		tiers = tiersDAO.findTiersByPrimaryKey(related_tiers_tieTiers, -1, -1);
		return "/jsf/caractpm/tiers/editTiers.xhtml";
	}

	/**
	 * Getter for variable CaractPM
	 * 
	 */
	@Transactional
	public Tiers getTiers() {
		return tiers;
	}

	/**
	 * View an existing Tiers entity
	 * 
	 */
	@Transactional
	public String selectCaractPMTiers(Integer caractpm_cpmTiers, Integer related_tiers_tieTiers) {
		tiers = tiersDAO.findTiersByPrimaryKey(related_tiers_tieTiers, -1, -1);
		return "/jsf/caractpm/tiers/viewTiers.xhtml";
	}

	/**
	 * Create a new CaractPM entity
	 * 
	 */
	@Transactional
	public String newCaractPM() {
		caractpm = new CaractPM();

		return "/jsf/caractpm/createCaractPM.xhtml";
	}

	/**
	 * Create a new Tiers entity
	 * 
	 */
	@Transactional
	public String newCaractPMTiers(Integer caractpm_cpmTiers) {
		tiers = new Tiers();

		return "/jsf/caractpm/tiers/createTiers.xhtml";
	}

	/**
	 * Delete an existing CaractPM entity
	 * 
	 */
	@Transactional
	public String deleteCaractPM(Integer cpmTiersKey) {
		CaractPM caractpm = caractPMDAO.findCaractPMByPrimaryKey(cpmTiersKey);
		caractPMService.deleteCaractPM(caractpm);
		return "/jsf/caractpm/listCaractPMs.xhtml";
	}

	/**
	 * Delete an existing Tiers entity
	 * 
	 */
	@Transactional
	public String deleteCaractPMTiers(Integer caractpm_cpmTiers, Integer related_tiers_tieTiers) {
		caractpm = caractPMService.deleteCaractPMTiers(caractpm_cpmTiers, related_tiers_tieTiers);

		return "/jsf/caractpm/viewCaractPM.xhtml";
	}

	/**
	 * Select the child Tiers entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteCaractPMTiers(Integer caractpm_cpmTiers, Integer related_tiers_tieTiers) {
		tiers = tiersDAO.findTiersByPrimaryKey(related_tiers_tieTiers);

		return "/jsf/caractpm/tiers/deleteTiers.xhtml";
	}

	/**
	 * Select an existing CaractPM entity
	 * 
	 */
	@Transactional
	public String selectCaractPM(Integer cpmTiersKey) {
		caractpm = caractPMDAO.findCaractPMByPrimaryKey(cpmTiersKey);

		return "/jsf/caractpm/viewCaractPM.xhtml";
	}

	/**
	 * Show all CaractPM entities
	 * 
	 */
	@Transactional
	public List<CaractPM> listCaractPMs() {
		return new java.util.ArrayList<CaractPM>(caractPMService.loadCaractPMs());
	}

	/**
	 * Save an existing Tiers entity
	 * 
	 */
	@Transactional
	public String saveCaractPMTiers(Integer caractpm_cpmTiers, Tiers tiers) {
		caractpm = caractPMService.saveCaractPMTiers(caractpm_cpmTiers, tiers);

		return "/jsf/caractpm/viewCaractPM.xhtml";
	}

	/**
	 * Getter for variable CaractPM
	 * 
	 */
	@Transactional
	public CaractPM getCaractpm() {
		return caractpm;
	}

	/**
	 * Edit an existing CaractPM entity
	 * 
	 */
	@Transactional
	public String editCaractPM(Integer cpmTiersKey) {
		caractpm = caractPMDAO.findCaractPMByPrimaryKey(cpmTiersKey);

		return "/jsf/caractpm/editCaractPM.xhtml";
	}

}
